{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <div class="d-flex justify-content-between align-items-center">
            <h2>知识文章列表</h2>
            <a href="{{ url_for('articles.create') }}" class="btn btn-primary">创建新文章</a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">所有文章</h5>
            </div>
            <div class="card-body">
                {% if articles %}
                <div class="list-group">
                    {% for article in articles %}
                    <div class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h5 class="mb-1">
                                <a href="{{ url_for('articles.view', id=article.id) }}" class="text-decoration-none">{{ article.title }}</a>
                            </h5>
                            <small>{{ article.created_at.strftime('%Y-%m-%d') }}</small>
                        </div>
                        <p class="mb-1">作者: <a href="{{ url_for('users.profile', id=article.author.id) }}" class="text-decoration-none">{{ article.author.name }}</a></p>
                        <div class="d-flex justify-content-between align-items-center">
                            <small>
                                {% for skill in article.skills %}
                                <a href="{{ url_for('articles.by_skill', skill_id=skill.id) }}" class="badge bg-secondary text-decoration-none">{{ skill.name }}</a>
                                {% endfor %}
                            </small>
                            <div>
                                {% if current_user.id == article.author.id or current_user.is_admin() %}
                                <a href="{{ url_for('articles.edit', id=article.id) }}" class="btn btn-sm btn-outline-primary">编辑</a>
                                <a href="{{ url_for('articles.delete', id=article.id) }}" class="btn btn-sm btn-outline-danger" onclick="return confirm('确定要删除此文章吗？');">删除</a>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted">暂无文章</p>
                <p>成为第一个分享知识的人！点击上方的"创建新文章"按钮开始撰写。</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}